package com.example.paimengshop.mypanes;

import com.example.paimengshop.dataclass.Commodity;
import javafx.scene.control.Label;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.HBox;
import javafx.scene.shape.Rectangle;
import javafx.scene.text.Font;

public class HomeWidget extends AnchorPane {

    private Commodity currentCommodity;

    private ImageView commodityView;

    private Label nameLabel;


    public HomeWidget(Commodity currentCommodity) {
        this.currentCommodity = currentCommodity;
        this.commodityView = new ImageView();

        commodityView.setImage(new Image(currentCommodity.getImageURL()));

        this.nameLabel = new Label(currentCommodity.getName());

        super.setPrefSize(300, 200);

        HBox hBox=new HBox();

        commodityView.setFitWidth(150);
        commodityView.setFitHeight(150);

        commodityView.setPreserveRatio(false);

        Rectangle rectangle = new Rectangle(commodityView.prefWidth(-1),commodityView.prefHeight(-1));
        rectangle.setArcWidth(30);
        rectangle.setArcHeight(30);
        commodityView.setClip(rectangle);


        nameLabel.setPrefSize(200, 150);
        nameLabel.setWrapText(true);
        nameLabel.setFont(new Font(20));
        nameLabel.setWrapText(true);

        hBox.getChildren().addAll(commodityView, nameLabel);

        super.getChildren().add(hBox);
    }
}
